# import requests
# url = 'https://wanandroid.com/user/login'
# payload={"username":"liangchao","password":"123456"}
# #进行请求
# re=requests.post(url=url,data=payload)
# #查看结果
# # print(re.text)
# # print(re.json())
# # print(re.headers)
#
# #cookie存到变量
# cookie=re.cookies
# #查看信息接口
# url2='https://wanandroid.com/user/login'
# #进行请求
# header={}
# header["Cookie"]="JSESSIONID=60DC1CAD9B6074155EB9A714D302E056"
# print(header)
# re2=requests.get(url=url2,cookies=cookie)
# print(re2.text)

# import requests
# url = 'https://wanandroid.com/user/login'
# payload={"username":"liangchao","password":"123456"}
# #进行请求
# s=requests.session()
# re=s.post(url=url,data=payload)
# print(re.text)
#
# url2='https://wanandroid.com/user/lg/userinfo/json'
# re2=s.get(url=url2)
# print(re2.status_code)
# print(re2.text)

"""
测试用例：
1.测试用例类继承unittest类
2.测试方法以test开头
"""


import unittest
from myfun import *

#创建一个测试类
class MyTest(unittest.TestCase):

    @unittest.skip('临时跳过这条用例')
    @unittest.skipIf(1==0,'满足条件则跳过该用例')
    @unittest.skipUnless(1==0,'满足条件，则执行该用例')
    #定义测试方法
    def test_add(self):
        print('执行test_add')
        real=add(1,2)
        self.assertEqual(real,4,'预期结果与实际结果不相当')

    def test_mul(self):
        self.skipTest('跳过该用例')
        print('执行test_mul')
        real=multi(1,2)
        self.assertEqual(real,2,'预期结果和测试结果相等')

    def setUp(self):
        print('这是一条测试用例执行前的准备工作')

    def tearDown(self):
        print('这是一条测试用例执行后的清理工作')

    @classmethod
    def tearDownClass(cls):
        print('所有用例执行后的清理工作')

    @classmethod
    def setUpClass(cls):
        print('所有用例的准备工作')



#测试
if __name__ == '__main__':
    # unittest.main(verbosity=2)

    #实例化，创建空测试套件
    suite=unittest.TestSuite()
    #调用实例方法
    suite.addTest(MyTest('test_mul'))
    suite.addTest(MyTest('test_add'))
    suite.addTests([MyTest('test_mul'),MyTest('test_add')])

    #实例化得到一个执行对象
    runner=unittest.TextTestRunner()
    #调用
    runner.run(suite)


